class Link
create
    make
feature { NONE }
    fdata : ANY
    next : Link
feature { ARRAYINTERFACE }
    make ( a : ANY)
    do
      Current.fdata:=a
      Current.next:=VOID
    end
    
    setNext(s : Link)
    do
        Current.next:=s
    end
    
    getNext() : Link
    do
        Result:=Current.next
    end
    
    data() : ANY
    do
        Result:=Current.fdata
    end
end


deferred class ARRAYINTERFACE
feature
    aget alias "[]" (s : INTEGER) : ANY
    deferred
    end
    
    aput (a : ANY)
    deferred
    end
end

class LINKEDLIST
inherit ARRAYINTERFACE
    rename aget as get,
           aput as put
    redefine get,put
create 
        make
feature {NONE}
        l : Link
        len : INTEGER
feature
    make
    do
        Current.l:=VOID
        Current.len:=0
    end
    
    get(s : INTEGER) : ANY
    local i,tmpi : INTEGER
          curlink : LINK
          prevfound,found : BOOLEAN
    do
       Result:=VOID
       from  i:=0
             found:=false
            curlink:=Current.l
       until  found
       loop
           found:= i=s
           prevfound:=found
           
           from  i:=i
           until not found
           loop
               Result:=curlink.data()
               found:=false
          end
           
           found:=prevfound
           
           from i:=i
           until found
           loop
               i:=i+1
               curlink:=curlink.getNext()
               found:=true
           end
           
           found:=prevfound
       end
    end
    
    put (a : ANY)
    local
        curlink,tmplink : Link
        i,tmpi: INTEGER
        is_first : BOOLEAN
    do
         !!curlink.make(a)
        -- Current.l:=curlink
        is_first:=false
       
        from i:=0
        until Current.l /= VOID
        loop
            !! curlink.make(a)
            Current.l:=curlink
            Current.len:=1
            is_first:=true
        end
        
       from i:=0
       until is_first 
       loop
            from curlink:=Current.l
            until curlink.getNext=VOID
            loop
                curlink:=curlink.getNext
            end
            !! tmplink.make(a)
            curlink.setNext(tmplink)
           is_first:=true
       end
    end
end

class PrecursorBase
create makeBase
feature
    makeBase
    do
       std_output.put_string("PrecursorBase%N")
    end
end

class PrecursorDerived
inherit PrecursorBase
        rename makeBase as makePrecursor
        redefine makePrecursor
create make
feature
       make
       do
          Current.makePrecursor
       end
       makePrecursor
       do
            std_output.put_string("PrecursorDerived%N")
            Precursor.makeBase
       end
end

class APP
feature
    INIT
    local
        a : LINKEDLIST
        f : PrecursorDerived
    do
       !!a.make
        a.put(2)
        a.put(1)
        a.put(3)
        std_output.put_integer({INTEGER}(a[0]));
        std_output.put_integer({INTEGER}(a[1]));
        std_output.put_integer({INTEGER}(a[2]));
        std_output.put_string("%N")
       !!f.make
    end
end
